package com.kuaimacode.kframework.api.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kuaimacode.kframework.mybatis.mapper.user.UserRechargeMapper;
import com.kuaimacode.kframework.mybatis.models.user.UserRecharge;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 中元
 * @date 2019/04/08
 */
@Service
public class UserRechargeService extends ServiceImpl<UserRechargeMapper, UserRecharge> {

    	/**
    	 *  分页查找所有的数据
    	 * @param pageNum 当前页码，从1开始
    	 * @param pageSize  一页显示多少行
    	 * @return
    	 */
    	public PageInfo<UserRecharge> findAll(int pageNum, int pageSize) {
    		PageHelper.startPage(pageNum, pageSize);
    		List<UserRecharge> datas = baseMapper.selectList(null);
    		return new PageInfo<UserRecharge>(datas);
    	}

		/**
		 *  分页查找用户所有的数据
		 * @param pageNum 当前页码，从1开始
		 * @param pageSize  一页显示多少行
		 * @return
		 */
		public PageInfo<UserRecharge> findAllByUserId(int pageNum, int pageSize, Long userId) {
			PageHelper.startPage(pageNum, pageSize);
			QueryWrapper<UserRecharge> qryWrapper = new QueryWrapper<>();
			qryWrapper.eq("user_id", userId);
			List<UserRecharge> datas = baseMapper.selectList(qryWrapper);
			return new PageInfo<UserRecharge>(datas);
		}


		/**
		 *  根据交易订单号查询
		 * @return
		 */
		public UserRecharge findByOutTradeNo(String outTradeNo) {
			QueryWrapper<UserRecharge> qryWrapper = new QueryWrapper<>();
			qryWrapper.eq("out_trade_no", outTradeNo);
			UserRecharge data = baseMapper.selectOne(qryWrapper);
			return data;
		}


}

